#include "loginwindow.h"
#include "ui_loginwindow.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <signal.h>
#include <QtDebug>
#include <QIcon>

loginWindow::loginWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::loginWindow)
{
    ui->setupUi(this);

    /* 自己写代码构造登录页面ui */

    QWidget *centralWidget = new QWidget(this);
    this->setCentralWidget(centralWidget);

    QVBoxLayout *vLayout = new QVBoxLayout(centralWidget);
    vLayout->addStretch(1);

    this->setStyleSheet("loginWindow{border-image: url(:/img/aaa.png);}");

    QHBoxLayout *hLayout = new QHBoxLayout();
    vLayout->addLayout(hLayout);

    hLayout->addStretch(1);

    QWidget *loginForm = new QWidget();
    QVBoxLayout *loginForm_VLayout = new QVBoxLayout(loginForm);
    loginForm_VLayout->addStretch(1);

    // 显示标签
    QLabel *lb = new QLabel(loginForm);

    lb->setFixedWidth(500);
    lb->setFixedHeight(80);
    lb->setText("图书管理系统");
    lb->setAlignment(Qt::AlignCenter);
    lb->setStyleSheet("font-size: 48px; color: rgb(255, 0, 0);");
    loginForm_VLayout->addWidget(lb);

    loginForm_VLayout->addSpacing(50);

    // 显示账号
    QLineEdit *account = new QLineEdit(loginForm);

    account->setFixedWidth(300);
    account->setFixedHeight(45);
    account->setMaxLength(12);
    account->setStyleSheet("font-size: 24px;");
    account->setPlaceholderText("请输入账号");
    loginForm_VLayout->addWidget(account, 0, Qt::AlignHCenter);

    loginForm_VLayout->addSpacing(20);

    // 显示密码
    QLineEdit *password = new QLineEdit(loginForm);

    password->setFixedWidth(300);
    password->setFixedHeight(45);
    password->setMaxLength(12);
    password->setEchoMode(QLineEdit::Password);
    password->setStyleSheet("font-size: 24px;");
    loginForm_VLayout->addWidget(password, 0, Qt::AlignHCenter);

    loginForm_VLayout->addSpacing(30);

    // 显示按钮
    QWidget *btnForm = new QWidget();

    QHBoxLayout *btnHLayout = new QHBoxLayout(btnForm);
    btnHLayout->addStretch(1);

    QIcon loginIcon(":/img/bbb.png");
    QPushButton *login_btn = new QPushButton(loginIcon, "登录", btnForm);

    login_btn->setIconSize(QSize(30,30));
    login_btn->setObjectName("login_btn");
    login_btn->setFixedWidth(100);
    login_btn->setFixedHeight(60);
    login_btn->setStyleSheet("#login_btn{background-color:rgb(255,255,255); font-size: 32px; border-radius: 15px;} QPushButton:pressed#login_btn{background-color:rgb(143,143,143);}");
    btnHLayout->addWidget(login_btn);
    connect(login_btn,SIGNAL(clicked()),this,SLOT(func()));  //手动连接信号槽

    btnHLayout->addStretch(1);

    QPushButton *register_btn = new QPushButton("注册", btnForm);
    register_btn->setObjectName("register_btn");
    register_btn->setFixedWidth(100);
    register_btn->setFixedHeight(60);
    register_btn->setStyleSheet("#register_btn{background-color:rgb(255,255,255); font-size: 32px; border-radius: 15px;} QPushButton:pressed#register_btn{background-color:rgb(143,143,143);}");
    btnHLayout->addWidget(register_btn);

    btnHLayout->addStretch(1);

    loginForm_VLayout->addWidget(btnForm);

    loginForm_VLayout->addStretch(1);

    hLayout->addWidget(loginForm);

    hLayout->addStretch(1);

    vLayout->addStretch(1);
}

loginWindow::~loginWindow()
{
    delete ui;
}

void loginWindow::func()
{
    qDebug() << "调用函数";
}
